package com.shopping_center.management.controller;


import com.github.pagehelper.PageInfo;
import com.shopping_center.management.common.DataWrapper;
import com.shopping_center.management.common.ResultCode;
import com.shopping_center.management.model.Car;
import com.shopping_center.management.model.Phone;
import com.shopping_center.management.service.PhoneService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RequestMapping("phone")
@RestController
@CrossOrigin
@Api(tags = "Phone")
@Slf4j
public class PhoneController {

    @Autowired
    private PhoneService phoneService;


    @PostMapping("/insertInToPhoneInfo")
    public DataWrapper<?> insertInToPhoneInfo(@Validated @RequestBody Phone phone) {
        phoneService.insertInToPhoneInfo(phone);
        return DataWrapper.successOf(ResultCode.SAVE_PHONE_INFO_SUCCESS);
    }

    @PostMapping("/selectAllPhoneInfo")
    public DataWrapper<?> selectAllCarInfo(int pageNum, int pageSize) {

        PageInfo<Phone> phones =  phoneService.selectAllPhoneInfo(pageNum, pageSize);
        return DataWrapper.successWithData(ResultCode.SELECT_ALL_PHONE_INFO, phones);
    }

    @PostMapping("/editPhoneInfo")
    public DataWrapper<?> editCarInfo(@Validated @RequestBody Phone phone) {
        phoneService.editPhoneInfo(phone);
        return DataWrapper.successOf(ResultCode.MODIFY_PHONE_INFO_SUCCESS);
    }

    @PostMapping("/deletePhoneInfoById")
    public DataWrapper<?> deletePhoneInfoById(String phoneId) {
        phoneService.deletePhoneInfoById(phoneId);
        return DataWrapper.successOf(ResultCode.DELETE_PHONE_INFO_SUCCESS);
    }
}
